﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Student_Score_System
{

    //单例模式
    public class StudentsSystem : Singleton<StudentsSystem>
    {
        private List<Student> StudentsList;
        public StudentsSystem()
        {
            InputManager = new UISystem(this);
            StudentsList = new List<Student>();
        }

        public UISystem InputManager;

        //执行开始函数
        /// <summary>
        /// 系统入口
        /// </summary>
        public void Start()
        {
            //画一个登录界面
            InputManager.LoginPanel();
            //InputManager.MainPanel();
        }

        //添加学生
        //public void AddStudent(Student s)
        //{
        //    Students.Add(s);
        //}
        //判断账号密码
        /// <summary>
        /// 验证账号密码
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool CheckAccountPassword(string account, string password)
        {
            if (account == "111111" && password == "88888")
            {
                return true;
            }
            return false;
        }

        //获取学生所在年级
        //public List<Student> GetStudents(E_GradeType grade)
        //{
        //    List<Student> ret = new List<Student>();
        //    for (int i = 0; i < StudentsList.Count; i++)
        //    {
        //        if (grade == StudentsList[i].Grade)
        //            ret.Add(StudentsList[i]);
        //    }
        //    return ret;
        //}

        //学生所在班级
        public List<Student> GetStudents(int cla)
        {
            List<Student> ret = new List<Student>();
            for (int i = 0; i < StudentsList.Count; i++)
            {
                if (cla == (int)StudentsList[i].Classs)
                    ret.Add(StudentsList[i]);
            }
            return ret;
        }

        //添加学生
        public void AddStudent(Student s)
        {
            if (IsHaveStudent(s))
            {
                Student temp = GetStudent(s.Id);
                temp = s;
            }
            else
            {
                StudentsList.Add(s);
            }
        }


        //查询学生信息
        /// <summary>

        /// 根据学号获取学生
        /// </summary>
        /// 
        /// <param name="id"></param>
        /// 
        /// <returns></returns>
        public Student GetStudent(int id)
        {
            for (int i = 0; i < StudentsList.Count; i++)
            {
                if (id == StudentsList[i].Id)
                    return StudentsList[i];
            }
            return null;
        }
        //删除学生
        /// <summary>

        /// 根据学号移除学生

        /// </summary>

        /// <param name="id"></param>
        public void RemoveStuden(int id)
        {
            for (int i = 0; i < StudentsList.Count; i++)
            {
                if (id == StudentsList[i].Id)
                {
                    StudentsList.RemoveAt(i);
                    return;
                }
            }
        }
        /// <summary>

        /// 获取指定年级的学生

        /// </summary>

        /// <param name="grade"></param>

        /// <returns></returns>

        public List<Student> GetStudents(E_GradeType grade)

        {
            List<Student> ret = new List<Student>();
            for (int i = 0; i < StudentsList.Count; i++)
            {
                if (StudentsList[i].Grade == grade)
                    ret.Add(StudentsList[i]);
            }
            return ret;
        }
        /// <summary>

        /// 获取指定年级所有成绩

        /// </summary>

        /// <param name="grade"></param>

        /// <returns></returns>

        public List<Score> GetScores(E_GradeType grade)

        {
            List<Score> ret = new List<Score>();
            for (int i = 0; i < StudentsList.Count; i++)
            {
                if (StudentsList[i].Grade == grade)
                    ret.Add(StudentsList[i].Score);
            }
            return ret;
        }
        /// <summary>

        /// 获取指定年级指定科目成绩

        /// </summary>

        /// <param name="grade"></param>

        /// <param name="course"></param>

        /// <returns></returns>

        public List<float> GetScores(E_GradeType grade, E_CourseType course)

        {
            List<float> ret = new List<float>();
            for (int i = 0; i < StudentsList.Count; i++)
            {
                ret.Add(StudentsList[i].Score.GetScore(course));
            }
            return ret;
        }
        //判断学生是否存在
        /// <summary>

        /// 判断学生是否存在

        /// </summary>

        /// <param name="s"></param>

        /// <returns></returns>
        public bool IsHaveStudent(Student s)
        {
            return IsHaveStudent(s.Id);
        }
        //判断学生id是否存在
        /// <summary>

        /// 判断学生是否存在

        /// </summary>

        /// <param name="id"></param>

        /// <returns></returns>
        public bool IsHaveStudent(int id)
        {
            for (int i = 0; i < StudentsList.Count; i++)
            {
                if (id == StudentsList[i].Id)
                    return true;
            }
            return false;
        }
        //检查ID姓名
        public bool CheckIdName(int  id, string name)
        {
            if ((id>0&&id<10000000)&& name == "88888")
            {
                return true;
            }
            return false;
        }

    }
}
